class Solution {
public:
    long long countBadPairs(vector<int>& nums) {
        unordered_map<int,int> window;
        int n = nums.size();
        long long ans = (long long)n * (n - 1) /2;
        for(int i = 0;i < n;i++)
        {
            ans -= window[nums[i] - i]++;
        }

        return ans;
    }
};